package com.ssy.lingxi.settle.accounts.model.constant;

import com.ssy.lingxi.common.constant.basic.PurchaseContractPayTypeEnum;
import com.ssy.lingxi.common.language.LanguageHolder;
import com.ssy.lingxi.dto.model.constant.SettlementHelpEnum;

import java.util.Arrays;
import java.util.Objects;

/**
 * 结算方式枚举
 * @author 伍将
 * @date 2020/10/21
 * @version 2.0.0
 */
public enum SettlementWayEnum {

    /**
     * 账期（默认）按天
     */
    ACCOUNT_PERIOD(1, "账期(按天)"),
    /**
     * 月结
     */
    MONTH_SETTLEMENT(2, "月结"),
    /**
     * 现结
     */
    CASH_SETTLEMENT(3, "现结"),
    /**
     * 账期（默认）按月
     */
    ACCOUNT_PERIOD_MONTH(4, "账期(按月)"),
    ;

    private final Integer code;
    private final String message;

    SettlementWayEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Integer getCode() {
        return code;
    }

    public String getMessage() {
        return LanguageHolder.getName(this.getDeclaringClass(), this.getCode());
    }

    public static String getMessage(Integer code) {
        return Arrays.stream(SettlementWayEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(ACCOUNT_PERIOD).getMessage();
    }

    public static Integer getNameByPurchaseContractPayTypeEnumCode(Integer code) {
        if (Objects.equals(code, PurchaseContractPayTypeEnum.CASH.getCode())) {
            return CASH_SETTLEMENT.code;
        } else if (Objects.equals(code, PurchaseContractPayTypeEnum.PERIOD_MONTHLY.getCode())) {
            return ACCOUNT_PERIOD_MONTH.code;
        } else if (Objects.equals(code, PurchaseContractPayTypeEnum.PERIOD_DAILY.getCode())) {
            return ACCOUNT_PERIOD.code;
        } else if (Objects.equals(code, PurchaseContractPayTypeEnum.MONTHLY.getCode())) {
            return MONTH_SETTLEMENT.code;
        } else {
            return 999;
        }
    }

    public static SettlementWayEnum getEnum(Integer code) {
        return Arrays.stream(SettlementWayEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(null);
    }

    public static String getMessage(Integer code,Integer settlementDays,Integer settlementDate) {
        String result= SettlementHelpEnum.UNKNOWN.getMessage();
        SettlementWayEnum settlementWayEnum = Arrays.stream(SettlementWayEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(null);
        if(settlementWayEnum!=null){
            if(settlementWayEnum.equals(ACCOUNT_PERIOD)){
                result= ACCOUNT_PERIOD.getMessage() + settlementDays + SettlementHelpEnum.DAY.getMessage();
            }else if(settlementWayEnum.equals(MONTH_SETTLEMENT)){
                result= ACCOUNT_PERIOD.getMessage() + settlementDate + SettlementHelpEnum.NO.getMessage();
            }else if(settlementWayEnum.equals(CASH_SETTLEMENT)){
                result= ACCOUNT_PERIOD.getMessage();
            }
        }
        return result;
    }
}
